<template>
  <el-dialog title="部门查询" :close-on-click-modal="false" :visible.sync="visible" fullscreen append-to-body center>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <div class="text item">
      <el-form inline size="mini">
        <el-form-item label="单位编码">
          <el-input v-model="dataForm.code"></el-input>
        </el-form-item>
        <el-form-item label="单位名称">
          <el-input v-model="dataForm.name"></el-input>
        </el-form-item>
        <!-- <el-form-item label="单位状态">
          <el-select v-model="dataForm.status">
            <el-option value="1" label="启用"></el-option>
            <el-option value="0" label="停用"></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-button icon="el-icon-search" type="primary" @click="getDataList">查询</el-button>
          <el-button icon="el-icon-delete" type="info" @click="clearSearchForm">清空</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-row style="margin-bottom: 3px;">
      <el-button type="primary" size="mini" @click="choiceAndClose">选择并关闭</el-button>
    </el-row>
    <el-table :data="dataList" height="calc(100vh - 215px)" ref="singleTable" border v-loading="dataListLoading" @selection-change="handleSelectionChange">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="code" header-align="center" align="center" label="单位编码"></el-table-column>
      <el-table-column prop="name" header-align="center" align="center" label="单位名称"></el-table-column>
    </el-table>
    <div class="avue-crud__pagination">
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        background
        layout="total, sizes, prev, pager, next">
      </el-pagination>
    </div>
  </el-dialog>
</template>

<script>
  import {filterParams} from '@/util/tools'
  import { unitquery } from '@/api/admin/unit'
  export default {
    data () {
      return {
        visible: false,
        selectionList: [],
        dataForm: {
          supplyId: '',
          supplyCode: '',
          supplyName: '',
          ctgId: '',
          status: ''
        },
        dataList: [],
        dataListLoading: false,
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0
      }
    },
    methods: {
      init() {
        this.visible = true
        this.getDataList()
      },
			clearSearchForm() {
				for(let key in this.dataForm){
					this.dataForm[key] = ''
				}
			},
      getDataList() {
        let params1 = {current: this.pageIndex,size: this.pageSize}
        let params2 = filterParams(this.dataForm)
        unitquery(Object.assign(params1,params2)).then(result => {
          this.dataList = result.data.data.records
          this.totalPage = result.data.data.total
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 选择品种
      checkitem(val) {
        this.visible = false
        this.$emit('refreshData',val)
      },
      //  多选表格改变事件
      handleSelectionChange(val) {
        this.selectionList = val
      },
      //  选择部门并关闭弹窗
      choiceAndClose() {
        this.visible = false
        this.$emit('refreshData',this.selectionList)
      }
    }
  }
</script>

<style>
</style>
